package com.opencvjava.zero;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

// 3 * 3
public class Unit {

    public static final int COLOR_FILL_THRESHOLD = 2;
    public static final int FILL_THRESHOLD = 2;

    private int midRow;
    private int midCol;
    private List<Integer> data = new ArrayList<>();
    private Set<Integer> colors = new HashSet<>();
    private UnitType unitType = UnitType.INIT;
    private VisitType visitType = VisitType.INIT;
    private Map<Integer, Unit> neighbours = new HashMap<>();
    private List<Integer> exits = new ArrayList<>();
    private int mean;

    public static void main(String[] args) {
        Unit edge = new Unit().setUnitType(UnitType.EDGE);
        Unit noise = new Unit().setUnitType(UnitType.NOISE);
        Unit colorFill = new Unit().setUnitType(UnitType.COLOR_FILL);
        Unit fill = new Unit().setUnitType(UnitType.FILL);
        System.out.println(edge.isColorFill());
        System.out.println(noise.isColorFill());
        System.out.println(colorFill.isFill());
        System.out.println(fill.isFill());
    }

    public enum VisitType {
        INIT, VISITED, MARKED
    }

    public enum UnitType {
        INIT, NOISE, EDGE, COLOR_FILL, FILL
    }

    public boolean isVisited() {
        return this.visitType.compareTo(VisitType.VISITED) > -1;
    }

    public boolean isMarked() {
        return this.visitType.compareTo(VisitType.MARKED) > -1;
    }

    public boolean isNoise() {
        return this.unitType.equals(UnitType.NOISE);
    }

    public boolean isColorFill() {
        return this.unitType.compareTo(UnitType.COLOR_FILL) > -1;
    }

    public boolean isFill() {
        return this.unitType.equals(UnitType.FILL);
    }

    public boolean isEdge() {
        return this.unitType.equals(UnitType.EDGE);
    }

    public Unit addExit(int exit) {
        this.exits.add(exit);
        return this;
    }

    public int exitSize() {
        return this.exits.size();
    }

    public Unit addNeighbours(Integer position, Unit unit) {
        this.neighbours.put(position, unit);
        return this;
    }

    public int colorSize() {
        return this.colors.size();
    }

    public Unit addData(int color) {
        this.data.add(color);
        return this;
    }

    public Unit addColor(int color) {
        this.colors.add(color);
        return this;
    }

    public UnitType getUnitType() {
        return unitType;
    }

    public Unit setUnitType(UnitType unitType) {
        this.unitType = unitType;
        return this;
    }

    public VisitType getVisitType() {
        return visitType;
    }

    public Unit setVisitType(VisitType visitType) {
        this.visitType = visitType;
        return this;
    }

    public Map<Integer, Unit> getNeighbours() {
        return neighbours;
    }

    public Unit setNeighbours(Map<Integer, Unit> neighbours) {
        this.neighbours = neighbours;
        return this;
    }

    public int getMidRow() {
        return midRow;
    }

    public Unit setMidRow(int midRow) {
        this.midRow = midRow;
        return this;
    }

    public int getMidCol() {
        return midCol;
    }

    public Unit setMidCol(int midCol) {
        this.midCol = midCol;
        return this;
    }

    public List<Integer> getData() {
        return data;
    }

    public Unit setData(List<Integer> data) {
        this.data = data;
        return this;
    }

    public Set<Integer> getColors() {
        return colors;
    }

    public Unit setColors(Set<Integer> colors) {
        this.colors = colors;
        return this;
    }

    public int getMean() {
        return mean;
    }

    public Unit setMean(int mean) {
        this.mean = mean;
        return this;
    }

    public List<Integer> getExits() {
        return exits;
    }

    public Unit setExits(List<Integer> exits) {
        this.exits = exits;
        return this;
    }
}
